import service.ReadWriteRunable;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;

public class WriteRunable extends ReadWriteRunable {
    private ByteBuffer byteBuffer;
    public WriteRunable(SocketChannel channel, ByteBuffer byteBuffer) {
        super(SelectionKey.OP_WRITE, channel);
        this.byteBuffer = byteBuffer;
    }

    @Override
    public void run() {
        if (byteBuffer != null && byteBuffer.limit() > 0) {
            try {
                super.getChannel().write(byteBuffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
